<?php
namespace app\admin\service;

use library\tools\Node;
use think\Db;
use think\facade\Request;

/**
 * 订单管理服务
 * Class OrderService
 * @package app\admin\service
 */
class OrderService
{
   

	/**
	 * 导出订单打印标签
     * @param array $id
     * @return array
     */
    public static function export_order_label($id)
    {
    	$filename = '订单打印标签列表';
    	$titles = array(
    		array('code','订单号'),
    		array('shop_name','所属店铺'),
    		array('create_order_at','下单日期'),
            array('clothing_info','衣服信息'), 
            array('screenshot','排单标记'),                     
        );
       
		//按照传入的ID顺序来查询数据库并输出
		$brandWeighString = implode(',', $id);
		$goodsOrder = 'FIELD(`id`, ' . $brandWeighString . ')';
        
    	$list = Db::name('system_order')->where(['id'=>$id])->orderRaw($goodsOrder)->field('id,code,shop_id,create_order_at,clothing,clothing_color,clothing_size,screenshot')->select();
    	
		if(!empty($list) && $list){
			$shops = get_all_shop();
			foreach($list as $k=>$v){
	    		$arr[$k]['code'] = $v['code'];
				$arr[$k]['shop_name'] = $shops[$v['shop_id']];
				$arr[$k]['create_order_at'] = $v['create_order_at'];
				$clothing = $v['clothing'] ? get_all_options('clothing')[$v['clothing']] : ''; 	
				$clothing_color = $v['clothing_color'] ? get_all_options('clothing_color')[$v['clothing_color']] : '';
				$clothing_size = $v['clothing_size'] ? get_all_options('clothing_size')[$v['clothing_size']] : '';
				$arr[$k]['clothing_info'] = $clothing.'-'.$clothing_color.'-'.$clothing_size;
				$arr[$k]['screenshot'] = $v['screenshot'];
	    	}
		}else{
			$arr = [];
		}   
    	
        return ['filename'=>$filename,'titles'=>$titles,'list'=>$arr];
    }


	
	/**
	 * 导出订单制作排单
     * @param array $id
     * @return array
     */
    public static function export_order_make_plan($id)
    {
    	$filename = '订单制作排单列表';
    	$titles = array(
    		array('code','订单号'),
    		array('shop_name','所属店铺'),
    		array('create_order_at','下单日期'),
            array('clothing_info','衣服信息'), 
            array('screenshot','排单标记'), 
            array('neckline_info','胸（领）口+线色'),
            array('chest_pic_img','胸口图片'), 
            array('sleeve_info','袖口+线色'),
            array('sleeve_pic_img','左袖口图片'),
            array('right_sleeve_pic_img','右袖口图片'), 
            array('custom_first_pic_img','实拍图片'), 
            array('desc','备注'),                   
        );
       
		//按照传入的ID顺序来查询数据库并输出
		$brandWeighString = implode(',', $id);
		$goodsOrder = 'FIELD(`id`, ' . $brandWeighString . ')';
        
    	$list = Db::name('system_order')
    			->where(['id'=>$id])
    			->orderRaw($goodsOrder)
    			->field('id,code,shop_id,create_order_at,clothing,clothing_color,clothing_size,screenshot,neckline,chest_line_color,sleeve,sleeve_line_color,claw_color,heart_color,chest_pic,sleeve_pic,right_sleeve_pic,custom_first_pic,desc')
    			->select();
    	
		if(!empty($list) && $list){
			$shops = get_all_shop();
			foreach($list as $k=>$v){
	    		$arr[$k]['code'] = $v['code'];
				$arr[$k]['shop_name'] = $shops[$v['shop_id']];
				$arr[$k]['create_order_at'] = $v['create_order_at'];
				$clothing = $v['clothing'] ? get_all_options('clothing')[$v['clothing']] : ''; 	
				$clothing_color = $v['clothing_color'] ? get_all_options('clothing_color')[$v['clothing_color']] : '';
				$clothing_size = $v['clothing_size'] ? get_all_options('clothing_size')[$v['clothing_size']] : '';
				$neckline = $v['neckline'] ? get_all_options('neckline')[$v['neckline']] : '';
				$chest_line_color = $v['chest_line_color'] ? get_all_options('chest_line_color')[$v['chest_line_color']] : '';
				$sleeve = $v['sleeve'] ? get_all_options('sleeve')[$v['sleeve']] : '';
				$sleeve_line_color = $v['sleeve_line_color'] ? get_all_options('sleeve_line_color')[$v['sleeve_line_color']] : '';
				$claw_color = $v['claw_color'] ? get_all_options('claw_color')[$v['claw_color']] : '';
				$heart_color = $v['heart_color'] ? get_all_options('heart_color')[$v['heart_color']] : '';
				$arr[$k]['clothing_info'] = $clothing.'-'.$clothing_color.'-'.$clothing_size;
				$arr[$k]['screenshot'] = $v['screenshot'];
				$arr[$k]['neckline_info'] = $neckline.'-'.$chest_line_color;
				$arr[$k]['chest_pic_img'] = $v['chest_pic'];				
				$arr[$k]['sleeve_info'] = $sleeve.'-'.$sleeve_line_color;
				if($heart_color){
					$heart = "心形-".$heart_color;
					$arr[$k]['sleeve_info'] = $arr[$k]['sleeve_info']."\n".$heart;
				}
				if($claw_color){
					$claw = "爪子-".$claw_color;
					$arr[$k]['sleeve_info'] = $arr[$k]['sleeve_info']."\n".$claw;
				}
				$arr[$k]['sleeve_pic_img'] = $v['sleeve_pic'];
				$arr[$k]['right_sleeve_pic_img'] = $v['right_sleeve_pic'];
				$arr[$k]['custom_first_pic_img'] = $v['custom_first_pic'];
				$arr[$k]['desc'] = $v['desc'];
	    	}
		}else{
			$arr = [];
		}   
    	
        return ['filename'=>$filename,'titles'=>$titles,'list'=>$arr];
    }
	
    
}
